package com.kakarote.admin.common;

import cn.hutool.core.util.StrUtil;

/**
 * @author zhangzhiwei
 * crm模块枚举
 */

public enum AdminEnum {
    /**
     * 角色
     */
    ROLE(1, "角色"),

    /**
     * 菜单
     */
    MENU(2, "菜单"),

    /**
     * NULL
     */
    NULL(0, "");

    AdminEnum(Integer type, String remarks) {
        this.type = type;
        this.remarks = remarks;
    }

    private final Integer type;
    private final String remarks;

    public String getRemarks() {
        return remarks;
    }

    public Integer getType() {
        return type;
    }

    public static AdminEnum parse(Integer type) {
        for (AdminEnum crmEnum : values()) {
            if (crmEnum.getType().equals(type)) {
                return crmEnum;
            }
        }
        return NULL;
    }

    public static AdminEnum parse(String name) {
        for (AdminEnum crmEnum : values()) {
            if (crmEnum.name().equals(name)) {
                return crmEnum;
            }
        }
        return NULL;
    }

    public String getIndex() {
        return "wukong_" + name().toLowerCase();
    }

    public String getTableName() {
        return name().toLowerCase();
    }

    /**
     * 获取主键ID
     *
     * @param camelCase 是否驼峰
     * @return primaryKey
     */
    public String getPrimaryKey(boolean camelCase) {
        String name;
        name = name().toLowerCase();
        if (camelCase) {
            return StrUtil.toCamelCase(name) + "Id";
        }
        return name + "_id";
    }

    public String getPrimaryKey() {
        return getPrimaryKey(true);
    }

    public String getLanguageKey() {
        return "{actionRecord." + StrUtil.toCamelCase(name().toLowerCase()) + "}";
    }

    @Override
    public String toString() {
        return this.type.toString();
    }
}
